package procilege.impl;

import java.util.logging.Logger;

import javax.xml.namespace.QName;

import merisis.sense.SenseMaker;

import procilege.Procilege;
import procilege.compiler.PalExprHelper;
import procilege.compute.ExprEvaluation;
import procilege.lang.Name;
import procilege.lang.PredicateExpr;

import com.google.inject.Inject;

public class ProcilegeImpl implements Procilege {

	@Inject
	private Logger logger;

	@Inject
	private ExprEvaluation reduction;

	@Inject
	private SenseMaker smr;

	@Inject
	private PalExprHelper hlp;
	
	@Inject
	private ComputationalEntityMgr cem;

	public boolean[] askAvailability(QName pid, QName cid, QName[] names,
			String content) {

		boolean[] result = new boolean[names.length];

		for (int i = 0; i < names.length; i++) {

			Name n = new NameImpl(smr.sense(names[i]));
			if (n == null) {

				result[i] = false;
				logger.info("unkown name: " + names[i]);
				continue;
			}

			PredicateExpr expr = hlp.privavail(hlp.privref(n));

			result[i] = (Boolean) reduction.eval(expr);
		}

		return result;
	}

	public void tell(QName pid, QName cid, String content) {

		cem.updateLiteralContent(content);
	}
}